package py.com.sole.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import py.com.sole.dao.DaoFactory;

@FacesConverter(value="personaConverter")
public class PersonaConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {

		if(value==null||value.equals("")){
			return null;
		}

		py.com.sole.model.Persona persona = new py.com.sole.model.Persona();
		persona = DaoFactory.getPersona().getPersonaByDocumento(value);
		return persona;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		if(value==null){
			return null;
		}
		py.com.sole.model.Persona persona = (py.com.sole.model.Persona)value;
		
		return persona.getDocumento();
	}

}
